#!/usr/bin/php
<?php
/*
 *  Copyright (c) 2014 Michał Żaloudik <michal.zaloudik@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
$version = '0.1';
$author = 'Michał Żaloudik <michal.zaloudik@gmail.com>';
/**
 *
 */
function print_help() {
	global $author, $version;
	$helptext = "php-svndumpfilter [options] < dump.file" . PHP_EOL;
	$helptext .= "Author: " . $author . PHP_EOL;
	$helptext .= "Version: " . $version . PHP_EOL;
	$helptext .= "Options:" . PHP_EOL;
	$helptext .= "\t--help, -h" . PHP_EOL;
	$helptext .= "\t-q" . PHP_EOL;
	$helptext .= "\t--version, -v" . PHP_EOL;
	$helptext .= "\t--drop-empty-revs" . PHP_EOL;
	$helptext .= "\t--preserve-revprops" . PHP_EOL;
	$helptext .= "\t--renumber-revs" . PHP_EOL;
	$helptext .= "\t--skip-missing-merge-sources" . PHP_EOL;
	echo $helptext;
}

/**
 *
 */
function print_version() {
	global $version;
	echo $version . PHP_EOL;
}

/**
 * @return string
 */
function fetch_dump_contents() {
	$stdin = fopen('php://stdin', 'r');
	$dump = '';
	while(!feof($stdin)) {
		$dump .= fgets($stdin, 4096);
	}
	return $dump;
}

/**
 * @param unknown $dump
 * @return array
 */
function map_dump($dump) {
	$dump_map = array();
	return $dump_map;
}

$shortopts = 'qvh';
$longopts = [
	'help',
	'version',
	'include:',
	'exclude:',
	'drop-empty-revs',
	'preserve-revprops',
	'renumber-revs',
	'skip-missing-merge-sources'
];

$options = getopt($shortopts, $longopts);

switch(true) {
	case (isset($options['include']) && !empty($options['include'])) || (isset($options['exclude']) && !empty($options['exclude'])):
		if(isset($options['include'])) {
			echo 'include: ' . $options['include'] . PHP_EOL;
		} else {
			echo 'exclude: ' . $options['exclude'] . PHP_EOL;
		}
		break;
	case isset($options['version']) || isset($options['v']):
		print_version();
		break;

	case isset($options['help']) || isset($options['h']):
	default:
		print_help();
		;
		break;
}
?>